package vim.meet.javassist;

import cn.freemethod.bean.WriteReadBusiness;
import javassist.util.proxy.ProxyFactory;
import javassist.util.proxy.ProxyObject;

public class JavassistStart {
    
    public static void main(String[] args) {
        ProxyFactory factory = new ProxyFactory();
        ReadWriteMethodFilter mf = new ReadWriteMethodFilter();
        factory.setFilter(mf);
        factory.setSuperclass(WriteReadBusiness.class);
        Class<?> clazz = factory.createClass();
        WriteReadBusiness instance = null;
        try {
            instance = (WriteReadBusiness)clazz.newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        ReadWriteHandler handler = new ReadWriteHandler();
        ((ProxyObject)instance).setHandler(handler);
        String result = instance.readSomething();
        System.out.println("client result:" + result);
        instance.writeSomething("write");
    }

}
